package com.xinnet.mms.utils;

import java.util.ArrayList;
import java.util.List;

import com.xinnet.core.utils.page.PageIndex;
import com.xinnet.core.utils.page.PageView;

/**
 * 重新分页
 * @author Administrator
 *
 * @param <E>
 */
public class AgainPageView<E> extends PageView<E>{
	/**
	 * 重新计算当前页数据
	 * @param records
	 */
	public void  againComputePageNowRecords(PageView<E> pageView,int tempPageNow,List<Object> records){
		if(records==null || records.size()==0){
			return;
		}
		int pageNowRecordsStartIndex;
		int pageNowRecordsEndIndex;
		if(tempPageNow==1){
			pageNowRecordsStartIndex=1;
		}else{
			pageNowRecordsStartIndex =(tempPageNow-1)*pageView.getPageSize()+1;
		}
		pageNowRecordsEndIndex = tempPageNow*pageView.getPageSize();
		pageView.setPageNow(tempPageNow);
		PageIndex pageIndex= new PageIndex(pageNowRecordsStartIndex,pageNowRecordsEndIndex);
		pageView.setPageindex(pageIndex);
		List<Object> tempRecords = new ArrayList<Object>();
		for (int i = 0; i < records.size(); i++) {
			if(i>=pageNowRecordsStartIndex-1 && i<=pageNowRecordsEndIndex-1){
				tempRecords.add(records.get(i));
			}
		}
		records.clear();
		records.addAll(tempRecords);
	}
	
	
	

}
